package com.lz.sports.utils

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.lz.sports.bean.ExamInspect
import com.lz.sports.bean.ExamResult
import com.lz.sports.bean.ExamSignIn
import com.lz.sports.bean.ExamSure

val gson: Gson by lazy {
    GsonBuilder()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .registerTypeAdapter(ExamInspect::class.java, ExamInspect.InspectSerializer())
        .registerTypeAdapter(ExamSignIn::class.java, ExamSignIn.ExamSignSerializer())
        .registerTypeAdapter(ExamResult::class.java, ExamResult.ExamResultSerializer())
        .registerTypeAdapter(ExamSure::class.java, ExamSure.ExamSureSerializer())
        .create()
}

fun Any.toGson(): String = gson.toJson(this)

inline fun <reified T> String.jsonToBean(): T? = gson.fromJson(this, T::class.java)

inline fun <reified T> String.jsonToList(): List<T> = gson.fromJson(this, object : TypeToken<List<T>>() {}.type)
